<%--
  Created by IntelliJ IDEA.
  User: qingx
  Date: 2018/12/29
  Time: 19:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="../base/top.jsp" %>

    <style>
        #result_admin{
            width: 90%;
            margin: auto;
            margin-top: 20px;
            padding: 20px;
            box-shadow: 0px 0px 3px #888888 ;
            border-radius: 5px;
            background-color: #FFFFFF;
        }
    </style>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <%--datatable--%>
                        <div id="result_admin">
                            <table id="data-table" width="100%" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        全选<input type="checkbox" id="check-all"/>
                                    </th>
                                    <th>序号</th>
                                    <th>学号</th>
                                    <th>姓名</th>
                                    <th>性别</th>
                                    <th>学业导师</th>
                                    <th>出生日期</th>
                                    <th>入学年份</th>
                                    <th>班级</th>
                                    <th>联系方式</th>
                                    <th>学籍状态</th>
                                    <th>挂科数</th>
                                    <th>用户</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                            <button class="btn btn-success" id="add" style="margin-top: 10px">新增</button>
                            <button class="btn btn-success" id="batchAddStudent" style="margin-top: 10px">批量录入学生信息</button>
                            <button class="btn btn-success" id="batchModifyFailNum" style="margin-top: 10px">批量修改学生挂科数</button>
                            <form id="uploadForm">
                                <input type="file" id="file" name="file"
                                       style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;"
                                       accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
                                <input type="file" id="modifyFile" name="modifyFile"
                                       style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;"
                                       accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
                            </form>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div>
<%@ include file="../base/foot.jsp" %>
<script>
    var table = null;
    var columnsData =  [
        {
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
        },
        {
            bSortable : false,
            data: null,
            width : "40px",
            className: 'text-center whiteSpace',
            render:function(data,type,row,meta) {
                return meta.row + 1 +
                    meta.settings._iDisplayStart;
            }
        },
        {'data': 'stuId',
            render:function(data,type,row,meta) {
                var html = "";
                html += "<a href='javascript:void(0);' onclick='showStudentDetail(this)'>"+data+"</a>";
                return html;
            }
        },
        {'data': 'stuName'},
        {'data': 'stuSex',
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                if(data==1){
                    return data = '女';
                }else{
                    return data = '男';
                }
            }
        },
        {'data': 'teaName',bSortable : false},
        {'data': 'stuBirth',
            bSortable : true,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return  moment(data).format("YYYY-MM-DD");
            }
        },
        {'data': 'stuEntryYear',
            bSortable : true,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return  moment(data).format("YYYY");
            }
        },
        {'data': 'stuClass'},
        {'data': 'stuTelephone',bSortable : false},
        {'data': 'stuEnrollmentState',bSortable : false},
        {'data': 'stuFailNumber'},
        {'data': 'userId'},
        {
            bSortable : false,
            className : "text-center",
            width : "100px",
            render : function(data, type, row, meta) {
                var id = '"' + row.id + '"';
                var html = "";
                html += "<a href='javascript:void(0);' onclick='edit(this)' class='up btn btn-primary btn-xs'><i class='fa fa-arrow-up'></i> Edit</a>";
                //  html += "<a href='javascript:void(0);'   onclick='deleteThisRowPapser("+ id + ")'  class='down btn btn-danger btn-xs'><i class='fa fa-arrow-down'></i> Delete</a>";
                return html;
            }
        }
    ];
    var dataBaseFiled =  [
        {'column2': 'pk_stu_id'},
        {'column3': 'stuName'},
        {'column6': 'stuBirth'},
        {'column7': 'stuEntryYear'},
        {'column8': 'stuClass'},
        {'column11': 'stuFailNumber'}
    ];
    var url='student/getList';
    var paramter = null;
    $(document).ready(function() {
        table = $('#data-table').DataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION,{

            columns:columnsData,
            // ajax: {
            //     type: 'post',
            //     url: 'label/getList'
            // }
            ajax: function (data,callback) {
                ajax(data,callback,dataBaseFiled,url,paramter);
            },
            order:[[ 2, "asc" ]]
        }));
    });

    $("#add").click(function () {
        window.location.href = "student/toAddStudent";
    });

    $("#batchAddStudent").click(function () {
        // 触发文件选择的click事件
        $("#file").trigger("click");
    });

    $("#file").change(function () {
            var form = new FormData(document.getElementById("uploadForm"));
            console.log(form);
            $.ajax({
                url:"student/batch_upload_student",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(data){
                    if(data["success"]==true){
                        alert(data["msg"]);
                        reloadDataTable();
                    }else{
                        alert(data["msg"]);
                    }
                },
                error:function(msg){
                    alert("学生上传失败！");
                }
            });
        }
    );

    $("#batchModifyFailNum").click(function () {
        // 触发文件选择的click事件
        $("#modifyFile").trigger("click");
    });

    $("#modifyFile").change(function () {
            var form = new FormData(document.getElementById("uploadForm"));
            console.log(form);
            $.ajax({
                url:"student/batch_upload_student_fail_number",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(data){
                    if(data["success"]==true){
                        alert(data["msg"]);
                        reloadDataTable();
                    }else{
                        alert(data["msg"]);
                    }
                },
                error:function(msg){
                    alert("挂科数修改失败！");
                }
            });
        }
    );

    function edit(button) {
        var studentInfo =  getClickedRowValue(button);
        window.location.href = "student/toModityStudent?stuId="+studentInfo["stuId"];
    }
    function showStudentDetail(button) {
        var json =  getClickedRowValue(button);
        window.location.href="<%= basePath%>student/viewStudentDetail?stuId="+json.stuId;
    }

</script>

</body>
</html>

